//
//  BigPicVC.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/7/4.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "BigPicVC.h"
#import "SDPhotoBrowser.h"
@interface BigPicVC ()<SDPhotoBrowserDelegate>

@property (weak, nonatomic) IBOutlet UIView *navBar;

@property (nonatomic, strong)UICollectionView * collectionView;
@end

@implementation BigPicVC


- (instancetype)initWithIndex:(NSInteger)index {
    self = [super init];
    if (self) {
        _index = index;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
     
    [self setup];

   
}



- (void)setup {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:layout];
    [self.view addSubview:self.collectionView];
    
    SDPhotoBrowser *photoBrowser = [SDPhotoBrowser new];
    
    photoBrowser.sourceImagesContainerView = self.collectionView;
    photoBrowser.imageCount = self.imageArray.count;
    photoBrowser.delegate = self;
    photoBrowser.currentImageIndex = self.index;
    [photoBrowser show];
    
    // ios 11  scrollvew 的位置调整
    if (@available(iOS 11.0, *)) {
        self.collectionView.contentInsetAdjustmentBehavior =UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
    
    return nil;
}

- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
    
    
    
    return [NSURL URLWithString:self.imageArray[index]];
}

- (void)photoBrowser:(SDPhotoBrowser *)browser setTitleForIndex:(NSInteger)index {
    NSString *title = self.imageName;
    self.title = title;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
